﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using BLL;
using ORMapping;
using DAL;

namespace TestUnit
{
    [TestFixture]
    public class TestUser
    {
        [Test]
        public void Query()
        {
            UserBLL user = new UserBLL();
            Assert.IsTrue(user.GetAllUsers("FROM User",new List<DAL.HQLParameter>()).Count > 0);
        }

        [Test]
        public void Add()
        {
            string strTemp = DateTime.Now.ToString("yyyyMMddhhmmss");
            UserBLL user = new UserBLL();
            User u = new User("测试", strTemp+"a", strTemp);
            //u.UserID = Int32.Parse(DateTime.Now.ToString("MMddhhmmss"));
            user.AddUser(u);
            List<DAL.HQLParameter> l = new List<DAL.HQLParameter>();
            l.Add(new DAL.HQLParameter(DAL.EnumHQLParameterType.STRING, "LoginName", u.LoginName.ToUpper()));
            Assert.IsTrue(user.GetAllUsers("FROM User u where u.LoginName = :LoginName",l).Count > 0);
        }

        [Test]
        public void Login()
        {
            UserBLL ub = new UserBLL();
            Assert.IsTrue(ub.Login("test","1111"));
            Assert.IsFalse(ub.Login("test4", "1111"));
        }

        [Test]
        public void UpdateUser()
        {
            string strTemp = DateTime.Now.ToString("yyyyMMddhhmmss");
            UserBLL user = new UserBLL();
            User u = new User(strTemp, strTemp+"a", strTemp);
            user.AddUser(u);
            u.Passwd = "1234";
            user.UpdateUser(u);
        }

        [Test]
        public void DeleteUser()
        {
            string strTemp = DateTime.Now.ToString("yyyyMMddhhmmss");
            UserBLL user = new UserBLL();
            User u = new User(strTemp, strTemp + "a", strTemp);
            u.UserID = 5;
            user.DeleletUser(u);
        }
    }
}
